package cc.iotkit.data.service;

import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.mapper.IJPACommData;
import cc.iotkit.data.manager.IHomeData;
import cc.iotkit.data.model.TbHome;
import cc.iotkit.model.space.Home;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Primary
@Service
public class HomeDataImpl implements IHomeData, IJPACommData<Home, String, TbHome> {

    @Resource
    private HomeService homeService;


    @Override
    public HomeService getBaseRepository() {
        return homeService;
    }

    @Override
    public Class getJpaRepositoryClass() {
        return TbHome.class;
    }

    @Override
    public Class getTClass() {
        return Home.class;
    }

    @Override
    public Home findByUidAndCurrent(String uid, boolean current) {
        return MapstructUtils.convert(homeService.findByUidAndCurrent(uid, current), Home.class);
    }

    @Override
    public Home findByUidAndId(String uid, String id) {
        return MapstructUtils.convert(homeService.findByUidAndId(uid, id), Home.class);
    }

    @Override
    public List<Home> findByUid(String uid) {
        return MapstructUtils.convert(homeService.findByUid(uid), Home.class);
    }
}
